package com.sample.util
{
	import flash.display.Graphics;
	import flash.filters.BlurFilter;
	import flash.geom.Rectangle;
	
	import mx.core.Application;
	import mx.core.FlexSprite;
	import mx.core.IFlexDisplayObject;
	import mx.core.UIComponent;
	import mx.managers.ISystemManager;
	import mx.managers.PopUpManager;
	import mx.styles.IStyleClient;
	
	public class UIUtil
	{
		public static function makeModal(popup:UIComponent):void {
			var modalSprite:FlexSprite = new FlexSprite();
			var screen:Rectangle = popup.screen;
			var systemManager:ISystemManager = popup.systemManager;
			
			systemManager.popUpChildren.addChildAt(modalSprite, systemManager.popUpChildren.getChildIndex(popup));
			
			var g:Graphics = modalSprite.graphics;
			var c:uint = popup.getStyle("modalTransparencyColor");
			modalSprite.alpha = popup.getStyle("modalTransparency");
			g.clear();
			g.beginFill(c, 100);
			g.drawRect(0,0,screen.width,screen.height);
			g.endFill();
			popup.parentApplication.filters = [new BlurFilter(popup.getStyle("modalTransparencyBlur"))];
		}
		
		public static function makeUnmodal(popup:UIComponent):void {
			popup.parentApplication.filters = [];
			popup.systemManager.popUpChildren.removeChildAt(popup.systemManager.popUpChildren.getChildIndex(popup) - 1);
		}
	}
}